﻿using System;
using System.Text.Json.Serialization;

namespace TowerCraneMonitorClient.NetClient.WorkCycle
{
    /// <summary>
    /// 吊装数据
    /// </summary>
    public class Entity : NetClient.Entity
    {
        /// <summary>
        /// 吊装开始时间。Json（unix时间戳）
        /// </summary>
        [JsonPropertyName("sTime")]
        public long StartTimeStamp => StartTime.ToUnixTimeStamp().ToLong();

        /// <summary>
        /// 吊装开始时间。常规时间
        /// </summary>
        [JsonIgnore]
        public DateTime StartTime { get; set; }


        /// <summary>
        /// 吊装结束时间。Json（unix时间戳）
        /// </summary>
        [JsonPropertyName("eTime")]
        public long EndTimeStamp => EndTime.ToUnixTimeStamp().ToLong();

        /// <summary>
        /// 吊装结束时间。常规时间
        /// </summary>
        [JsonIgnore]
        public DateTime EndTime { get; set; }


        /// <summary>
        /// 吊装过程中最大载重(吨)
        /// </summary>
        public float MaxWeight { get; set; }


        /// <summary>
        /// 吊装过程中最大载重百分比
        /// </summary>
        public float MaxWeightper { get; set; }


        /// <summary>
        /// 吊装过程中最大力矩（吨·米）
        /// </summary>
        public float MaxForce { get; set; }


        /// <summary>
        /// 吊装过程中最大力矩百分比
        /// </summary>
        public float MaxForceper { get; set; }


        /// <summary>
        /// 塔机吊装开始的转角
        /// </summary>
        [JsonPropertyName("sAngle")]
        public float StartAngle { get; set; }


        /// <summary>
        /// 塔机吊装结束转角
        /// </summary>
        [JsonPropertyName("eAngle")]
        public float EndAngle { get; set; }


        /// <summary>
        /// 塔机吊装开始变幅
        /// </summary>
        [JsonPropertyName("sExtent")]
        public float StartExtent { get; set; }


        /// <summary>
        /// 塔机吊装结束变幅
        /// </summary>
        [JsonPropertyName("eExtent")]
        public float EndExtent { get; set; }

        /// <summary>
        /// 本次吊装的最大变幅
        /// </summary>
        public float MaxExtent { get; set; }

        /// <summary>
        /// 本次吊装最小变幅
        /// </summary>
        public float MinExtent { get; set; }


        /// <summary>
        /// 本次吊装的开始高度
        /// </summary>
        [JsonPropertyName("sHeight")]
        public float StartHeight { get; set; }


        /// <summary>
        /// 本次吊装的结束高度
        /// </summary>
        [JsonPropertyName("eHeight")]
        public float EndHeight { get; set; }

        /// <summary>
        /// 本次吊装的最大高度
        /// </summary>
        public float MaxHeight { get; set; }

        /// <summary>
        /// 本次吊装的最小高度
        /// </summary>
        [JsonPropertyName("minHeight")]
        public float MinHeight { get; set; }


        /// <summary>
        /// 驾驶舱内是否有驾驶员(1有，0没有)
        /// </summary>
        public IsDriver IsDriver { get; set; }


        /// <summary>
        /// 驾驶员身份证号
        /// </summary>
        public string DriverId => DriverInfo.IDCard;

        /// <summary>
        /// 驾驶员姓名
        /// </summary>
        public string DriverName => DriverInfo.Name;


        /// <summary>
        /// 电源状态。0：正常供电, 1：备用电源供电
        /// </summary>
        public PowerStatus Power { get; set; }


        /// <summary>
        /// 本次吊装的最大风速
        /// </summary>
        public float MaxWind { get; set; }

        /// <summary>
        /// 本次吊装的最大倾角(动臂塔机),如没有传递0
        /// </summary>
        public float MaxElevation { get; set; }

        /// <summary>
        /// 本次吊装的最小倾角(动臂塔机),如没有传递0
        /// </summary>
        public float MinElevation { get; set; }


        /// <summary>
        /// 本次吊装的状态
        /// </summary>
        public Status Status { get; set; }

        [JsonIgnore]
        public DriverInfo.Entity DriverInfo { get; set; }

        /// <summary>
        /// 基于该对象生成 WorkCycle.Req 报文
        /// </summary>
        /// <param name="errorMessage">失败时返回错误信息，成功时返回 null</param>
        /// <returns>成功时返回 WorkCycle.Req 对象，失败时返回 null</returns>
        public new Req ToReq() => new Req(this);
    }
}
